package com.yehui.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
import org.springframework.stereotype.Service;

@Service
public class MyInstantiationAwareBeanPostProcessor implements InstantiationAwareBeanPostProcessor {

    public MyInstantiationAwareBeanPostProcessor(){
        System.out.println("MyInstantiationAwareBeanPostProcessor=============");
    }

    //初始化之前进行后置处理,Sring留给我们这个组件创建对象的回调
    @Override
    public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
        System.out.println("MyInstantiationAwareBeanPostProcessor=================");
        return null;//如果我们自己创建了对象返回，Spring则不会帮我们创建对象，用我们自己创建的对象
    }

    //初始化之后进行后置处理
    @Override
    public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
        System.out.println("MyInstantiationAwareBeanPostProcessor================");
        return true;//返回false则bean赋值全部结束
    }

    @Override//解析自定义注解进行属性赋值注入，pvs封装了所有的属性信息
    public PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName) throws BeansException {
        System.out.println("postProcessProperties==============");
        return null;
    }
}
